clear all

disp('Commands to compute stuff')
disp(' ')

set(text,'FontSize',2);

%*****************************************
%
% .. Global Parameters ..
%
%averz=0.5015*4
%delta=0.96
%q0=.01
%q0=1.0/(q0+1.0)
%debtfactor=1.0/((1.0-q0*delta)*4.0)

filename = 'partd\results\events\defeventsparam.dat';
delimiterIn = ' ';
headerlinesIn = 1;
myparam = importdata(filename,delimiterIn,headerlinesIn);
myparam.data;
myparam;
myparam.textdata;

delta=myparam.data(:,1);
q0=myparam.data(:,2);
freq=myparam.data(:,3);
averz=myparam.data(:,4);
averz=averz*freq
debtfactor=1.0/((1.0-q0*delta)*freq);

tmin=0;
tmax=10; %11; % 50;

min1=0.8 
max1=1.2

min2=0.0 
max2=1.01


%min3=(0.033*4/averz )*debtfactor;
%max3=(0.065*4/averz)*debtfactor;
%min3=(0.01/averz )*debtfactor;
%max3=(0.065/averz)*debtfactor;
min3=0.2;
max3=0.6;
min4=(0.0012*4/averz )*debtfactor;
max4=(0.0022*4/averz)*debtfactor
min4=(0.00*4/averz )*debtfactor;
max4=(0.0025*4/averz)*debtfactor


min5=0.00
max5=1.00

min6=0.00*100 
max6=0.10*100

%********************************************************
mydata = importdata('partd\results\events\defevents_lenyr8.dat', ' ',4 );
mydata.data;
mydata;
mydata.textdata;

time=mydata.data(:,1);
y=mydata.data(:,2)/averz;
z=mydata.data(:,3)/averz;
a=(mydata.data(:,4)/averz)*debtfactor;
b=mydata.data(:,5)/averz;
dtoa=mydata.data(:,6); %/averz;
spr=mydata.data(:,7); %/averz;
c=mydata.data(:,8)/averz;
zero=0;

b=b*debtfactor;

%********************************************************
%mydata = importdata('referencemodel\barg\calibration\case7\example_case7(5)\events\defevents_lenyr2.dat', ' ',4 );
mydata = importdata('barg\events\defevents_lenyr2.dat', ' ',4 );
mydata.data;
mydata;
mydata.textdata;

time2=mydata.data(:,1);
y2=mydata.data(:,2)/averz;
z2=mydata.data(:,3)/averz;
a2=(mydata.data(:,4)/averz)*debtfactor;
b2=mydata.data(:,5)/averz;
dtoa2=mydata.data(:,6); %/averz;
spr2=mydata.data(:,7); %/averz;
c2=mydata.data(:,8)/averz;
zero=0;

b2=b2*debtfactor
%********************************************



% plot(time,spr,'b-',time,spr2,'r--','LineWidth',2); 
% set(gca,'FontSize',12)
% axis([ tmin tmax, min6 max6 ]);
% text(time(1550),spr2(1501),'Spread','FontSize',14,'Color','k');
% line([tshock tshock], [0.9 2.5]);


figure(1); 

subplot(3,2,1);
plot(time,c,'b-',time,c2,'r--','LineWidth',2);
set(gca,'FontSize',10)
axis([ tmin tmax, min1 max1  ]);
text(time(8), z(10)+.2,' Consumption','FontSize',12,'Color','k');
line([1 1], [min1 max1]);

subplot(3,2,2);
plot(time,y,'b-',time,y2,'r--','LineWidth',2); 
set(gca,'FontSize',10)
axis([ tmin tmax, min1 max1 ]);
text(time(8), y(10)+.2,'Output','FontSize',12,'Color','k');
line([1 1], [min1 max1]);

% subplot(3,2,2);
% plot(time,c,'b-','LineWidth',2); 
% axis([ tmin tmax, 0.485 0.495  ]);
% legend ('C','Location','SouthEast');
% line([1501 1501], [0.485 0.495]);

subplot(3,2,3);
plot(time,a,'b-',time,a2,'r--','LineWidth',2); 
set(gca,'FontSize',10)
axis([ tmin tmax, min3 max3 ]);
text(time(4), b(10)+.2,'Debt','FontSize',12,'Color','k'); 
line([1 1], [min3 max3]);

subplot(3,2,4);
plot(time,b,'b-',time,b2,'r--','LineWidth',2); 
set(gca,'FontSize',10);
axis([ tmin tmax, min4 max4  ]);
text(time(3), b(10)-.02,'Borrowing','FontSize',12,'Color','k')
%xlabel('years '); 
line([1 1], [min4 max4]);

subplot(3,2,5);
 plot(time,dtoa,'b-',time,dtoa2,'r--','LineWidth',2); 
 set(gca,'FontSize',10);
 text(time(3), dtoa(10)+0.1,'Partial Default','FontSize',12,'Color','k')
 axis([ tmin tmax, min5 max5  ]);
 line([1 1], [min5 max5]);

subplot(3,2,6);
plot(time,spr*100,'b-',time,spr2*100,'r--','LineWidth',2);
set(gca,'FontSize',10)
 text(time(3), spr(10)*100+1,'Spread','FontSize',12,'Color','k')
axis([ tmin tmax, min6 max6  ]);
line([1 1], [min6 max6]);

%print -djpeg modelcomparison\slides\defevents_len-8-2.jpg
fig2=figure(2) 
figure(2)
subplot(1,3,1);
 plot(time,dtoa,'b-',time,dtoa2,'r--','LineWidth',2); 
 set(gca,'FontSize',10);
 text(6,.9,'Partial Default','FontSize',11,'Color','k')
  text(time(3), .7,'Renegotiation Reference','Interpreter','latex' ,'FontSize',12, 'Color','r')
   text(time(4), .4,'Baseline','FontSize',12,'Interpreter','latex','Color','b')
 axis([ tmin tmax, min5 max5  ], 'square');
 line([1 1], [min5 max5],'Color','black','LineStyle','--');

 subplot(1,3,2);
plot(time,a,'b-',time,a2,'r--','LineWidth',2); 
set(gca,'FontSize',10)
axis([ tmin tmax, 0.2 1.0 ], 'square');
text(6,.9,'Debt','FontSize',12,'Color','k'); 
line([1 1], [0.2 1.0] ,'Color','black','LineStyle','--');
%print -dpdf modelcomparison\slides\defevents_len-8-2.pdf
 
subplot(1,3,3);
plot(time,c,'b-',time,c2,'r--','LineWidth',2);
set(gca,'FontSize',10)
axis([ tmin tmax, .72 1.05  ], 'square');
text(6,1.0,' Consumption','FontSize',12,'Color','k');
line([1 1], [.72 1.05],'Color','black','LineStyle','--');

orient(fig2,'landscape')
print(fig2,'event_compare_new.pdf','-dpdf')

return;

